g= input()
 
if len(str(g)) != 4:
    print(0)
else:
    gh = False
    for length in range(4, 0, -1):
        if gh:
            break
        for i in range(4 - length + 1):
            hg = int(str(g)[i:i+length])
            if hg < 2:
                continue
            for j in range(2, int(hg**0.5) + 1):
                if hg % j == 0:
                    break
            else:
                print(hg)
                gh = True
                break
    if not gh:
        print(0)
